package mta.patch;

import mta.localization.LocalizationPackage;
import mta.localization.ModulePhrase;

import java.util.HashMap;

/**
 * Magento Translation Assistant
 * Copyright (c) 2009 Dmitry Nikolaev
 * Contact author: blackliteon@gmail.com
 */
public class PatchUntranslated implements ModulePhrasePatchIF {

    private LocalizationPackage loc;
    private HashMap<String, String> patch;

    public PatchUntranslated(LocalizationPackage loc, HashMap<String, String> patch) {
        this.loc = loc;
        this.patch = patch;
    }

    public String getTranslation(ModulePhrase mPhrase) {
        String original = mPhrase.getPhrase();

        if (loc.hasTranslationForModulePhrase(mPhrase)) {
            return loc.getTranslationForModulePhrase(mPhrase);
        }

        if (patch.containsKey(original)) {
            String translation = patch.get(original);
            if (!translation.isEmpty()) {
                return translation;
            }
        }
        return null;
    }
}
